<template>
  <a-input v-bind="$attrs" @click="openFn" v-model:value="txtValue" :disabled="props.isAdd && isUpdate"
    placeholder="请选择ms部门">
    <template #suffix>
      <CloseCircleOutlined @click="clearFn" />

    </template>
  </a-input>
  <!--  <a-button type="primary" style="margin-top: 10px" v-if="props.isAdd&&isUpdate">添加人员</a-button>-->
  <DataList @register="registerModal" @success="handleSuccess" :mode="props.mode"></DataList>
</template>

<script lang="ts" setup>
import DataList from './index.vue';
import { useModal } from "@/components/Modal";
import { ref, computed, watch } from "vue";
import { useMessage } from "@/hooks/web/useMessage";
import { CloseCircleOutlined } from '@ant-design/icons-vue';

import { useUserStore } from '@/store/modules/user';
const userStore = useUserStore();


defineOptions({ name: 'Ainput' });
const props = defineProps({
  mode: { type: String, default: "multiple" },
  ids: { type: String, default: "" },
  isAdd: { type: Boolean, default: false },
  value: { type: String, default: "" },
});
const emit = defineEmits(['change', 'update:value', "success"]);
const [registerModal, { openModal }] = useModal();
const { createMessage } = useMessage();
//userStore.chatIsUpdate
const isUpdate = computed(() => { return userStore.chatIsUpdate });
const options = ref([])
// const txtValue = computed(() => { return props.value });
const txtValue = ref("");

watch(() => props.value, (val) => {
  txtValue.value = val

})

function openFn() {
  // console.log("---props.mode222",props.mode)
  //console.log("--ids::",props.ids)
  openModal(true, { ids: props.ids })
}

function clearFn(e) {
  txtValue.value = "";
  let result = { ids: "", names: "" };
  emit("success", result);
}


function handleSuccess(list) {


  let ids = [];
  let names = [];

  // let option=[];
  list.forEach(e => {
    names.push(e.name)
    ids.push(e.tid)
  });
  let ids_str = ids.join(",");
  let result = { ids: ids_str, names: names.join(",") };
  // console.log("--result:", result)
  emit("success", result)
  // options.value=option;

}
function onLoadDataFn(ids) {
  // console.log("---接收数据:",ids)
}
</script>

<style scoped></style>
